package String;

public class _788_RotatedDigits {
    public int rotatedDigits(int N) {
        int count = 0;
        for (int i = 1; i <=N; i++) {
            char[] number = String.valueOf(i).toCharArray();
            boolean rotate = false;
            for (int j = 0; j < number.length; j++) {
                if (number[j] == '5' || number[j] == '2' || number[j] == '6' || number[j] == '9') {
                    rotate = true;
                } else if (number[j] == '3' || number[j] == '4' || number[j] == '7') {
                    rotate = false;
                    break;
                }
            }
            if (rotate == true) {
                count++;
            }
        }
        return count;
    }
}
